package com.css.project.weixin.controller;

import java.util.List;

import com.css.project.weixin.service.IUserWeixinRelaService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.css.framework.aspectj.lang.annotation.Log;
import com.css.framework.aspectj.lang.enums.BusinessType;
import com.css.project.weixin.domain.Members;
import com.css.project.weixin.service.IMembersService;
import com.css.framework.web.controller.BaseController;
import com.css.framework.web.domain.AjaxResult;
import com.css.common.utils.poi.ExcelUtil;
import com.css.framework.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author css
 * @date 2020-06-30
 */
@RestController
@RequestMapping("/weixin/members")
public class MembersController extends BaseController
{
    @Autowired
    private IMembersService membersService;
    @Autowired
    private IUserWeixinRelaService userWeixinRelaService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('my:members:list')")
    @GetMapping("/list")
    public TableDataInfo list(Members members)
    {
        startPage();
        List<Members> list = membersService.selectMembersList(members);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('my:members:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Members members)
    {
        List<Members> list = membersService.selectMembersList(members);
        ExcelUtil<Members> util = new ExcelUtil<Members>(Members.class);
        return util.exportExcel(list, "members");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('my:members:query')")
    @GetMapping(value = "/{uId}")
    public AjaxResult getInfo(@PathVariable("uId") Long uId)
    {
        return AjaxResult.success(membersService.selectMembersById(uId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('my:members:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Members members)
    {
        return toAjax(membersService.insertMembers(members));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('my:members:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Members members)
    {
        return toAjax(membersService.updateMembers(members));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('my:members:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/del")
    public AjaxResult remove(@PathVariable Long[] uIds,@PathVariable Long weinxinId)
    {
        //先删除微信绑定关系表数据
        userWeixinRelaService.deleteUserWeixinRelaById(weinxinId);
        return toAjax(membersService.deleteMembersByIds(uIds));
    }
}
